<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 130px;
            height: 130px;
            background-color: #000;
            color: #fff;
            font-size: 13px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
  <center>  属性名：<input type="text"><br>
    属性值: <input type="text"><br>
    <button>确定</button><button>重置</button>
</center>
<p></p>
<div id="div1">
    在上方输入框输入"属性名"及"属性值"，点击确定按钮查看效果。
</div>
<script>
    var changeStyle = function (elem,name,value){
        elem.style[name] = value
    }
    window.onload = function (){
        var div1 = document.getElementById('div1')
        var btn =document.getElementsByTagName('button')
        var inp = document.getElementsByTagName('input')
        btn[0].onclick = function (){
            alert(1)
            changeStyle(div1,inp[0].value,inp[1].value)
        },
        btn[1].onclick = function(){
            div1.removeAttribute('style')
        }
    }


</script>
</body>
</html>